from cryptography.fernet import Fernet


# TODO 要自定义加解密就在这里实现
def encrypt_file(key, sfn, ofn):
    with open(sfn, "rb") as sf:
        with open(ofn, "wb") as of:
            of.write(Fernet(key).encrypt(sf.read()))


def decrypt_file(key, sfn, ofn):
    with open(sfn, "rb") as sf:
        with open(ofn, "wb") as of:
            of.write(Fernet(key).decrypt(sf.read()))


def encrypt(key, d):
    return Fernet(key).encrypt(d)


def decrypt(key, d):
    return Fernet(key).decrypt(d)


def generate_key():
    return Fernet.generate_key()
